<template>
  <div>
    <FormPanel  ref="formPanel"
        :list="initForm"   
        :cols="3"          
        :labelWidth="120"  
        :isSubmitBtn="false"  
        @formChange="formChangeHandle"
        class="mtop"
     />
     <div class="dialogBottmView">
      <el-button @click="closeDialog">取 消</el-button>
      <el-button @click="saveDialog" type="primary">保 存</el-button>
    </div>
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import { PHONE_PATTERN } from '@/utils/validate' // 验证
export default {
  mixins: [dictionary],
  data() {
    return {
      initForm : this.initFormFun(),
      formValue : {}
    };
  },
  methods: {
    //初始化数据
    init(data){
     this.formValue={}
     if(data.type==='edit'){
       this.initForm.forEach(x => {
          x.initialValue = data.row[x.fieldName];
        });
      }
    },
    //搜索数据
    initFormFun(){
        return [{
              type: 'INPUT',
              label: '客户公司名称',
              fieldName: 'field1',
              placeholder: '请输入',
              initialValue: '',
              rules: [{
                required: true,
                message: '必填',
                trigger: 'blur'
              }]
            },
            {
              type: 'SELECT',
              label: '客户类型',
              fieldName: 'field2',
              placeholder: '请选择',
              initialValue: "",
              itemList: this.createDictList('1008')
            },
            {
              type: 'SELECT',
              label: '客户性质',
              fieldName: 'field3',
              placeholder: '请选择',
              initialValue: "",
              itemList: this.createDictList('1008')
            },
            {
              type: 'SELECT',
              label: '客户状态',
              fieldName: 'field4',
              placeholder: '请选择',
              initialValue: "",
              itemList: this.createDictList('1008')
            },
            {
              type: 'SELECT',
              label: '客户来源',
              fieldName: 'field5',
              placeholder: '请选择',
              initialValue: "",
              itemList: this.createDictList('1008')
            },
            {
              type: 'DATE',
              label: '建档时间',
              fieldName: 'field6',
              valueFormat: 'yyyy-MM-dd',
              initialValue: '',
              placeholder: '请选择'
            },
            {
              type: 'SELECT',
              label: '省份',
              fieldName: 'field7',
              placeholder: '请选择',
              initialValue: "",
              change: (value) => {
                console.log(value)
              },
              itemList: this.createDictList('1008'),
              rules: [{
                required: true,
                message: '必填',
                trigger: 'blur'
              }]
            },
            {
              type: 'SELECT',
              label: '市',
              fieldName: 'field8',
              placeholder: '请选择',
              initialValue: "",
              itemList: this.createDictList('1008')
            },
            {
              type: 'SELECT',
              label: '区',
              fieldName: 'field9',
              placeholder: '请选择',
              initialValue: "",
              itemList: this.createDictList('1008')
            },
            {
              type: 'TEXT_AREA',
              label: '详细地址',
              fieldName: 'field10',
              rows: 1,
              initialValue: '',
              placeholder: '请输入'
            },
            {
              type: 'SELECT',
              label: '所属行业分类',
              fieldName: 'field11',
              placeholder: '请选择',
              initialValue: "",
              itemList: this.createDictList('1008')
            },
            {
              type: 'SELECT',
              label: '行业地位',
              fieldName: 'field12',
              placeholder: '请选择',
              initialValue: "",
              itemList: this.createDictList('1008')
            },
            {
              type: 'SELECT',
              label: '采购方式',
              fieldName: 'field13',
              placeholder: '请选择',
              initialValue: "",
              itemList: this.createDictList('1008')
            },
            {
              type: 'SELECT',
              label: '意向车型',
              fieldName: 'field14',
              placeholder: '请选择',
              initialValue: "",
              itemList: this.createDictList('1008')
            },
            {
              type: 'INPUT_NUMBER',
              label: '预计采购数量',
              fieldName: 'field141',
              placeholder: '请输入',
              initialValue: '',
            },
            {
              type: 'SELECT',
              label: '购车用途',
              fieldName: 'field15',
              placeholder: '请选择',
              initialValue: "",
              itemList: this.createDictList('1008')
            },
            {
              type: 'DATE',
              label: '预计采购日期',
              fieldName: 'field16',
              valueFormat: 'yyyy-MM-dd',
              initialValue: '',
              placeholder: '请选择'
            },
            {
              type: 'SELECT',
              label: '预算来源',
              fieldName: 'field17',
              placeholder: '请选择',
              initialValue: "",
              itemList: this.createDictList('1008')
            },
            {
              type: 'INPUT_NUMBER',
              label: '年度预算',
              fieldName: 'field171',
              placeholder: '请输入',
              initialValue: '',
              precision: 2
            },
            {
              type: 'SELECT',
              label: '上牌城市',
              fieldName: 'field18',
              placeholder: '请选择',
              initialValue: "",
              itemList: this.createDictList('1008')
            },
            {
              type: 'SELECT',
              label: '是否跨区销售',
              fieldName: 'field19',
              placeholder: '请选择',
              initialValue: "",
              itemList: this.createDictList('1008')
            },
            {
              type: 'INPUT',
              label: '融资渠道',
              fieldName: 'field20',
              placeholder: '请输入',
              initialValue: ''
            },
            {
              type: 'INPUT',
              label: '客户关键联系人',
              fieldName: 'field21',
              placeholder: '请输入',
              initialValue: '',
              rules: [{
                required: true,
                message: '必填',
                trigger: 'blur'
              }]
            },
            {
              type: 'INPUT',
              label: '联系方式',
              fieldName: 'field22',
              placeholder: '请输入',
              initialValue: '',
              rules: [{
                required: true,
                message: '必填',
                trigger: 'blur'
              }, {
                pattern: PHONE_PATTERN,
                message: '手机格式不正确',
                trigger: 'blur'
              }]
            },
            {
              type: 'TEXT_AREA',
              label: '备注',
              fieldName: 'field23',
              rows: 2,
              initialValue: '',
              placeholder: '请输入'
            }
          ]
    },
    formChangeHandle(val){
      this.formValue=val
    },
    //保存
    saveDialog(){
      this.$emit('close', {visible:false,});
    },
    //取消操作
    closeDialog(){
      this.$emit('close', {visible:false,});
    }
  },
}
</script>